<template>
  <div v-if="shenheStatus == 0" class="box">
    <div class="title">
      <view @click="changeNav(-1)" :class="current == -1 ? 'current' : ''">{{
        $t('person.cashStatus1')
      }}</view>
      <view @click="changeNav(3)" :class="current == 3 ? 'current' : ''">{{
        $t('goods.good')
      }}</view>
      <view @click="changeNav(2)" :class="current == 2 ? 'current' : ''">{{
        $t('goods.general')
      }}</view>
      <view @click="changeNav(1)" :class="current == 1 ? 'current' : ''">{{
        $t('goods.bad')
      }}</view>
    </div>
    <commentList :list="evaluateList"></commentList>
    <view class="noMore">没有更多了~</view>
    <!-- 全局过渡组件 -->
    <transitionPage></transitionPage>
  </div>
  <Shenhe v-else-if="shenheStatus == 1"></Shenhe>
</template>

<script>
import Shenhe from '@/components/shenhe/shenhe';
import commentList from './components/comment-list.vue';
export default {
  data() {
    return {
      // 评价列表
      evaluateList: [],
      // 评价总数
      comment_count: {},
      page: 1,
      // 没有更多数据了
      noMore: false,
      // 商品id
      goods_id: 0,
      // 当前处于导航
      current: -1,
    };
  },
  components: {
    commentList,
    Shenhe,
  },
  computed: {},
  watch: {},
  onReachBottom() {
    if (!this.noMore) {
      this.page++;
      this.getEvaluateList();
    }
  },
  methods: {
    async getEvaluateList() {
      var param = {
        goods_id: this.goods_id,
        page: this.page,
        score: this.current,
      };
      const res = await this.$allrequest.goods.commentList(param, true);
      if (res.code == 0) {
        this.evaluateList = [...this.evaluateList, ...res.data.list];
        if (this.evaluateList.length >= res.data.row_count) {
          this.noMore = true;
        } else {
          this.noMore = false;
        }
      }
    },
    // 切换导航
    changeNav(e) {
      if (e != this.current) {
        this.current = e;
        this.page = 1;
        this.noMore = false;
        this.evaluateList = [];
        this.getEvaluateList();
      }
    },
  },
  onLoad(t) {
    this.goods_id = t.goods_id;
    this.getEvaluateList();
    uni.setNavigationBarTitle({
      title: this.$t('title.comment'),
    });
  },
};
</script>

<style scoped lang="less">
.box {
  width: 100%;
  min-height: 100vh;
  padding-top: 148rpx;
  background-color: #fff;
  .title {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 124rpx;
    display: flex;
    align-items: center;
    background: #ffffff;
    padding: 0 36rpx;
    border-bottom: 24rpx solid #f2f2f2;
    view {
      width: 104rpx;
      height: 52rpx;
      border-radius: 99px;
      background-color: #fdf1f0;
      font-size: 24rpx;
      color: #262626;
      font-family: PingFang SC;
      text-align: center;
      line-height: 52rpx;
      margin-right: 20rpx;
    }
    .current {
      color: #f0250e;
      border: 1px solid #f60313;
    }
  }
  .noMore {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 40rpx;
    font-size: 22rpx;
    font-family: PingFang SC;
    color: #c1c1c1;
  }
}
</style>
